package com.atguigu.dga.common;

import com.squareup.okhttp.Call;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;

public class HttpUtil {


    private static OkHttpClient okHttpClient= new OkHttpClient(); //饿汉 99%应用程序员的选择



    public static   String  get(String url){
        //构造器模式
        Request request = new Request.Builder().get().url(url).build();
        //创建一个会话·
        Call call = okHttpClient.newCall(request);
        try {
            Response response = call.execute(); //执行会话
            return response.body().string();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        String json = HttpUtil.get("http://hadoop102:18080/api/v1/applications/application_1682967712307_0019/1/stages/2");
        System.out.println("json = " + json);
    }


}
